package com.wntms.zjy.web;

import com.github.pagehelper.PageInfo;
import com.wntms.zjy.pojo.CustomerReply;
import com.wntms.zjy.pojo.FreightContract;
import com.wntms.zjy.pojo.Result;
import com.wntms.zjy.service.FreightContractService1;
//import jdk.nashorn.internal.objects.annotations.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xzbz
 * @create 2022-11-27 23:09
 */
@RestController
@RequestMapping("/fc")
public class FreightContractController1 {

    @Autowired
    private FreightContractService1 freightContractService1;

    @GetMapping("/{currentPage}/{pageSize}")
    public Result findByPage(@PathVariable Integer currentPage,@PathVariable Integer pageSize){
        List<FreightContract> freightContracts = freightContractService1.findByPage(currentPage, pageSize);
        if(freightContracts == null){
            return Result.error("服务器错误");
        }else{
            PageInfo<FreightContract> pageInfo = new PageInfo<>(freightContracts);

            return Result.success(pageInfo,"执行成功");
        }
    }

    @GetMapping
    public Result findAll(){
        List<FreightContract> freightContracts = freightContractService1.findAll();
        if(freightContracts == null){
            return Result.error("服务器错误");
        }else{

            return Result.success(freightContracts,"执行成功");
        }
    }
    @GetMapping("/{fid}")
    public Result findById(@PathVariable String fid){
        FreightContract freightContract = freightContractService1.findById(fid);
        if(freightContract == null){
            return Result.error("服务器错误");
        }else{

            return Result.success(freightContract,"执行成功");
        }
    }

    @PostMapping
    public Result findCount(){
        Integer count = freightContractService1.findCount();
        return Result.success(count,"执行成功");

    }

}
